var express = require('express'); //引入express模块  
var app = express();

var bodyParser = require('body-parser'); //request对象解析
var cookieParser = require('cookie-parser'); //request操作cookie
app.use(bodyParser());
app.use(cookieParser());
var server = require('http').createServer(app);
var io = require('socket.io').listen(server); //引入socket.io模块并绑定到服务器

// app.use('/', express.static(__dirname + '../public/')); //指定静态HTML文件的位置  

/*
 * 连接数据库ORM
 */
var orm = require("./orm");
app.use(orm);

var multipart = require('connect-multiparty'); // form-data,req.files
app.use(multipart());

var router = require("./router")(app); // 路由指定路径
server.listen(1104); //指定服务端口在1104
/*
 * socket通信部分
 */
io.on('connection', function(socket) {
	//接收并处理客户端发送的foo事件  
	// socket.on('foo', function(data) {
	// 	//将消息输出到控制台  
	// 	console.log(data);
	// 	socket.emit("req", "hahaha")
	// });
	socket.on("sendfile", function(data) {
		console.log(data);
		socket.broadcast.emit("receive", data);
	});
	socket.on("video", function(data) {
		console.log(data);
		socket.broadcast.emit("videochat", data);
	});
});
console.log("server started in 1104");